<?php
ob_start();
session_start();
include_once('postgre.php');

$usr = addslashes($_POST['whoareyou']);
$pwd = addslashes($_POST['yoursecret']);

if (isset($_POST['what']))
    $what = $_POST['what'];
if (isset($_GET['what']))
    $what = $_GET['what'];

if ($what == 'inn') {
	 /*	$h = get_datas("select distinct a.id_uslevel, a.id_skpd, a.namaakun, a.pass, a.id_bidang 
						from mus_akun a, user_level l, mus_skpd s, mus_bidang_bappeda b
						where a.id_uslevel=l.id_uslevel or ((s.id_skpd=a.id_skpd) or (a.id_bidang=b.id_bdgbapeda)) and a.namaakun='" . $usr . "' and a.pass='" . $pwd . "'");    
		*/
	
	 $h = get_data("select * from mus_akun where namaakun='" . $usr . "' and pass='" . $pwd . "'");    
	 
    if (count($h) > 0) {   
 	if($h['id_skpd'] != 0){
			$skpd = get_data("select id_skpd, kode_skpd, nama_skpd from mus_skpd where id_skpd=".$h['id_skpd']);
		 	$_SESSION['_idskpd'] = $skpd['id_skpd'];
			$_SESSION['_kode'] = $skpd['kode_skpd'];
		 	$_SESSION['_skpd'] = $skpd['nama_skpd'];
			$_SESSION['_username'] = $h['namaakun'];
			$_SESSION['_idakun'] = $h['id_akun'];
			$_SESSION['_pass'] = $h['pass'];
			$_SESSION['_namapj'] = $h['nama_pj'];
			$_SESSION['_nip'] = $h['nip_akun'];
			$_SESSION['_iduslevel'] = $h['id_uslevel'];
		} else if($h['id_bidang'] != 0){
			$bdg = get_data("select id_bdgbapeda, nama_bdgbapeda from mus_bidang_bappeda where id_bdgbapeda=".$h['id_bidang']);
		 	$_SESSION['_idbidang'] = $bdg['id_bdgbapeda'];
		 	$_SESSION['_nmbidang'] = $bdg['nama_bdgbapeda'];
			$_SESSION['_username'] = $h['namaakun'];
			$_SESSION['_idakun'] = $h['id_akun'];
			$_SESSION['_pass'] = $h['pass'];
			$_SESSION['_namapj'] = $h['nama_pj'];
			$_SESSION['_nip'] = $h['nip_akun'];
			$_SESSION['_iduslevel'] = $h['id_uslevel'];
		}
		 else if ($h['id_kecamatan'] !=0){
			$kec = get_data("select id_kecamatan, nama_kecamatan from mus_kecamatan where id_kecamatan=".$h['id_kecamatan']);
			$_SESSION['_idkec'] = $kec['id_kecamatan'];
			$_SESSION['_kec'] = $kec['nama_kecamatan'];
			$_SESSION['_username'] = $h['namaakun'];
			$_SESSION['_idakun'] = $h['id_akun'];
			$_SESSION['_pass'] = $h['pass'];
			$_SESSION['_namapj'] = $h['nama_pj'];
			$_SESSION['_nip'] = $h['nip_akun'];
			$_SESSION['_iduslevel'] = $h['id_uslevel'];
		 
		 }
		else {  
			$_SESSION['_username'] = $h['namaakun'];
			$_SESSION['_idskpd'] = $h['id_skpd'];
			$_SESSION['_iduslevel'] = $h['id_uslevel'];
			$_SESSION['_idakun'] = $h['id_akun'];
		}
	  echo 'suk___admindata.php';
    } else {
        echo 'gal';
    }
	
	logs('Login');
}else if ($what == 'outt'){
    unset($_SESSION['_kode']);
    unset($_SESSION['_skpd']);
    unset($_SESSION['_username']);
    unset($_SESSION['_idskpd']);
    session_destroy();
    echo 'ko';
	logs('Logout');
}
?>